package com.lemon.file.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import com.lemon.common.security.annotation.RequiresPermissions;
import com.lemon.file.domain.BiFileFolder;
import com.lemon.file.service.IBiFileFolderService;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.utils.poi.ExcelUtil;

/**
 * 文件夹管理Controller
 * 
 * @author huangpeng
 * @date 2022-12-18
 */
@RestController
@RequestMapping("/folder")
public class BiFileFolderController extends BaseController
{
    @Autowired
    private IBiFileFolderService biFileFolderService;

    /**
     * 查询文件夹管理列表
     * @Title: list
     * @Description: 查询文件夹管理列表
     * @param biFileFolder
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/12/18 19:11
     */
    // 暂时去掉权限 @RequiresPermissions("file:folder:list")
    @GetMapping("/list")
    public AjaxResult list(BiFileFolder biFileFolder)
    {
        List<BiFileFolder> list = biFileFolderService.selectBiFileFolderList(biFileFolder);
        return AjaxResult.success(list);
    }

    /**
     * 导出文件夹管理列表
     * @Title: export
     * @Description: 导出文件夹管理列表
     * @param response
     * @param biFileFolder
     * @return: void
     * @throws:
     * @author: huangpeng
     * @Date: 2022/12/18 19:11
     */
    @RequiresPermissions("file:folder:export")
    @Log(title = "文件夹管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BiFileFolder biFileFolder)
    {
        List<BiFileFolder> list = biFileFolderService.selectBiFileFolderList(biFileFolder);
        ExcelUtil<BiFileFolder> util = new ExcelUtil<BiFileFolder>(BiFileFolder.class);
        util.exportExcel(response, list, "文件夹管理数据");
    }

    /**
     * 获取文件夹管理详细信息
     * @Title: getInfo
     * @Description: 获取文件夹管理详细信息
     * @param id
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/12/18 19:11
     */
    @RequiresPermissions("file:folder:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(biFileFolderService.selectBiFileFolderById(id));
    }

    /**
     * 新增文件夹管理
     * @Title: add
     * @Description: 新增文件夹管理
     * @param biFileFolder
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/12/18 19:11
     */
    @RequiresPermissions("file:folder:add")
    @Log(title = "文件夹管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BiFileFolder biFileFolder)
    {
        return toAjax(biFileFolderService.insertBiFileFolder(biFileFolder));
    }

    /**
     * 修改文件夹管理
     * @Title: edit
     * @Description: 修改文件夹管理
     * @param biFileFolder
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/12/18 19:12
     */
    @RequiresPermissions("file:folder:edit")
    @Log(title = "文件夹管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BiFileFolder biFileFolder)
    {
        return toAjax(biFileFolderService.updateBiFileFolder(biFileFolder));
    }

    /**
     * 删除文件夹管理
     * @Title: remove
     * @Description: 删除文件夹管理
     * @param ids
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/12/18 19:12
     */
    @RequiresPermissions("file:folder:remove")
    @Log(title = "文件夹管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(biFileFolderService.deleteBiFileFolderByIds(ids));
    }
}
